var changePwd = function(){
	this.box = $("#formpage");	//表单
	this.input = this.box.find("span.at_text>input");
	
	this.p = $("#password1");		//密码
	this.pCheck = false;
	this.p1 = $("#password2");		//确认密码
	this.p1Check = false;
	this.p2 = $("#password");		//当前密码
	this.p2Check = false;
	
	this.btn = $("#reg_sub");	//提交按钮

	var me = this;  //page  1新增 2修改 
	
	var isloading=false;
	
	//提示信息
	var h_on='<em class="on">';	
	var h_err = '<em class="orr"><u class="at_msg m_3_e"></u>';
	var h_pas = '<u class="at_passking"><s class="at_txt">安全等级：</s><s class="at_bar"><span></span><span></span><span class="at_end"></span></s></u>';
	
	
	var same_pas='·密码不能包含用户名<br />';
	var pas_o = h_on+'<u class="at_msg m_3_i"></u>'+h_pas+'<br class="clear" />·密码由6~16位字母、数字或特殊符号组成</em>';	
	var pas_o1 = h_on+'·再一次输入新密码</em>';
	var pas_o2 = h_on+'·请输入新密码</em>';
	var pas_o2 = h_on+'·请输入您的当前密码</em>';
	
	//错误
	var p_e2 = h_err+'请输入当前密码</em>';
	var p_e = h_err+'新密码不能为空</em>';
	var p_e1 = h_err+'请再次输入新密码</em>';
	
	//正确
	var name_g = '<em><u class="at_msg m_3_o"></u></em>';
	var name_ld = '<em class="ld"><u class="at_msg at_write"></u>正在检测中……</em>';
	
	var pas_e1_n = '两次输入的密码不一致'; 
	var pas_e1 = h_err+pas_e1_n+'</em>';
	var pas_e2 = h_err+'密码不能为空</em>';
	var pas_e3 = h_err+'密码应为6-16个字符</em>';
	var pas_e4_n = '密码太过简单';
	var pas_e4 = h_err+pas_e4_n+'</em>';
	var pas_e5_n = '密码不能是用户名的一部分';
	var pas_e5 = h_err+pas_e5_n+'</em>';
	
	var opas_in_n = '当前密码输入错误！';
	var opas_in = h_err+opas_in_n+'</em>';

	function txt(t){var a=t.parents(".at_text");return a};	
	this.input.focus(function(){//获得焦点
		txt($(this)).attr("class","at_text t_1_i");		
		txt($(this)).find("em").remove();	
		$(this).parents("dd").css("z-index",999);
	})
	this.input.blur(function(){//失去焦点
		txt($(this)).attr("class","at_text t_1_d");
		txt($(this)).find("em").remove();
		$(this).parents("dd");
	})	
	var inErr = function(a,b){//错误
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_e");
		at_text.find("em").remove();
		at_text.append(b);
		return false;
	}
	var inOk = function(a){//正确
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_o");
		at_text.find("em").remove();
		at_text.append(name_g);
	}
	var inPass = function(a){//正常，不加“正确”图标
		var at_text = txt(a);
		at_text.attr("class","at_text t_1_o");
		at_text.find("em").remove();
		//at_text.append(name_g);
	}
	
	var namelength = function(a) {//统计字符长度，中文算二个字符
		var name = a.val(),
			length = 0;
		for(var i=0; i<name.length; i++) {
			if(/[\u4e00-\u9fa5]/.test(name.charAt(i))) length+=2;
			else length+=1;
		}
		return length;
	};
	
	var strTrimLength = function(a) {//统计字符长度，不包括空格在内
		var name = a.val(),
			length = 0;
		name=$.trim(name);
		for(var i=0; i<name.length; i++) {
			if(/[\u4e00-\u9fa5]/.test(name.charAt(i))) length+=2;
			else length+=1;
		}
		return length;
	};
		
	var clearEmpty = function(O) {//禁止输入空格
		O.val(O.val().replace(/\s*/g,""));
	}
	
	this.opasCheck = function(i,s){//当前密码	
		clearEmpty(i);
		var len = strTrimLength(i);
        if (len == 0) {
        	me.p2Check = inErr(i,p_e2);			
			return;
        }
		inPass(i);				
		me.p2Check = true;
		if(s) me.regIn();
	}

	this.pasCheck = function(i,s){//新密码
		clearEmpty(i);
		var password = i.val();
		var len = strTrimLength(i);
        if (len == 0) {
        	me.pCheck = inErr(i,p_e);			
			return;
        } else if(!/^.{6,16}$/.test(password)) {//6-16字符
			me.pCheck=inErr(i,pas_e3);
			return;
		}
		inPass(i);				
		me.pCheck = true;
		if(s) me.regIn();
	}
	
	this.pasCheck1 = function(i,s){//确认密码
		clearEmpty(i);
		var len = strTrimLength(i);
       	if (len == 0) {
       		me.p1Check = inErr(i,p_e1);			
			return;
       	}
       	
		if(me.p.val()!='') {			
			if(i.val()!=me.p.val()){				
				me.p1Check=inErr(i,pas_e1);
			}else{
				inPass(i);
				me.p1Check=true;
			}
		}
		if(s) me.regIn();
	}
	
	this.btn.click(function(){//按钮提交
	    if(isloading){return false;}
		if(me.p2Check==false){
			me.opasCheck(me.p2,false);
		}
		if(me.pCheck==false){
			inPass(me.p);
			me.pasCheck(me.p,false);
		}
		if(me.p1Check==false){
			inPass(me.p1);
			me.pasCheck1(me.p1,false);
		}
		if(!me.p2Check || !me.pCheck || !me.p1Check) return false;
		me.regIn();
		return true;
	})
	
	this.regIn = function(){
		at_loading.show();
		isloading=true;	
		$.ajax({
		    url: "ajaxUser_changePwd.do",
		    type:"POST",
		    data:me.box.serialize(),
		    success:function(json){
		        isloading=false;	
		        if(json.retcode=='0000'){
		        	at_loading.hide();
		        	at_infoTrace.show(json.retmsg,"i");
		        	me.box[0].reset();
		        	clearForm();
		        }else{
		            at_loading.hide();
		            at_infoTrace.show(json.retmsg,"e");
		        }
		    }
		});
	}
	
	//重置表单
	var clearForm = function(){
		inPass(me.p);
		inPass(me.p1);
		inPass(me.p2);
	};
	
	this.p.focus(function(){
		me.pCheck=false;
	})
	this.p.blur(function(){me.pasCheck(me.p)})	
	
	this.p1.focus(function(){
		me.p1Check=false;
	})
	this.p1.blur(function(){me.pasCheck1(me.p1)})

	this.p2.focus(function(){
		me.p2Check=false;
	})
	this.p2.blur(function(){me.opasCheck(me.p2)})
	
	//第一个控件获得焦点
	//this.input.eq(0).focus();	
}
